/**
 * 站点路由：机构和个人建立自己的站点
 * 2022.02.09
 */
import Request from '@/utils/request'
import Layout from '@/views/site/layout'
let templatePath ='views/site/template1' //  模板路径
let title = ''
export default {
    path: '/site/:userId',   // 站点首页,userId:机构或者个人用户id
    component: Layout,
    redirect: { name: 'SiteIndex' }, // 重定向到
    name: 'Site',
    meta:{
      title:'站点'
    },
    beforeEnter:async (to, from ,next)=>{ // 路由前置钩子：获取站点名称（即机构名称）和模板目录
      //console.log("路由独享的钩子:",to, from)
      const res = await Request.post('/app/user/'+to.params.userId)
      //console.log("用户信息：",res.data)
      if(res.data.code == 200){
        const siteInfo = res.data.data  // 当前站点信息，即机构信息
        templatePath =`views/site/template${siteInfo.templateId}`
        title = siteInfo.name
        to.meta.title = title
      }
      next()
    },
    children:[
      {
        path: 'index',
        name: 'SiteIndex',
        component: () => import(/* webpackChunkName: "SiteIndex" */ `@/${templatePath}/index`),
        //meta: { title: `${title}-站点首页` }
        beforeEnter:(to, from ,next)=>{
          to.meta.title = `${title}`
          next()
        }
      },
      {
        path: 'course',
        name: 'SiteCourse',
        component: () => import(/* webpackChunkName: "SiteCourse" */ `@/${templatePath}/course`),
        //meta: { title: `${title}-课程中心` }
        beforeEnter:(to, from ,next)=>{
          to.meta.title = `${title}-课程中心`
          next()
        }
      },
      {
        path: 'course/:id',   // 课程详情
        name: 'SiteCourseDetials',
        component: () => import(/* webpackChunkName: "SiteCourseDetials" */ `@/${templatePath}/course/details.vue`),
        beforeEnter:(to, from ,next)=>{
          to.meta.title = `${title}-课程详情`
          next()
        } 
      },
      {
        path: 'course/:id/:type/:level',   // 团购、分销课程详情
        name: 'SiteCourseDetials2',
        component: () => import(/* webpackChunkName: "SiteCourseDetials2" */ `@/${templatePath}/course/details.vue`),
        beforeEnter:(to, from ,next)=>{
          to.meta.title = `${title}-课程详情`
          next()
        } 
      },
      {
        path: 'pay/order',   // 支付订单
        name: 'SitePayOrder',
        meta:{
          title:'确认订单'
        },
        component: () => import(/* webpackChunkName: "SitePayOrder" */ `@/${templatePath}/order`)
      },
      {
        path: 'course/recommends',   // 推荐课程列表
        name: 'SiteCourseRecommend',
        component: () => import(/* webpackChunkName: "SiteCourseRecommend" */ `@/${templatePath}/course/recommend.vue`),
        beforeEnter:(to, from ,next)=>{
          to.meta.title = `${title}-推荐课程`
          next()
        }  
      },
      {
        path: 'course/live',   // 直播列表
        name: 'SiteCourseLive',
        meta:{
          title:'直播课程'
        },
        component: () => import(/* webpackChunkName: "SiteCourseLive" */ `@/${templatePath}/course/Live.vue`)
      },
      {
        path: 'means',
        name: 'SiteMeans',
        component: () => import(/* webpackChunkName: "SiteMeans" */ `@/${templatePath}/means`),
        beforeEnter:(to, from ,next)=>{
          to.meta.title = `${title}-资料中心`
          next()
        }
      },
      {
          path: 'article',   // 文章列表
          name: 'SiteArticle',
          meta:{
            title:'文章列表'
          },
          component: () => import(/* webpackChunkName: "SiteArticle" */ `@/${templatePath}/article/index`)
      },
      {
        path: 'article/:id',   // 文章详情
        name: 'SiteArticleDetails',
        meta:{
          title:'文章详情'
        },
        component: () => import(/* webpackChunkName: "SiteArticleDetails" */ `@/${templatePath}/article/details`)
      },
      {
        path: 'qa',
        name: 'SiteQa',
        component: () => import(/* webpackChunkName: "SiteQa" */ `@/${templatePath}/qa`),
        meta: { title: `在线咨询` }
      },
      {
        path: 'qa/:id',   // 问答详情
        name: 'SiteQaDetails',
        meta:{
          title:`问答详情`
        },
        component: () => import(/* webpackChunkName: "SiteQaDetails" */ `@/${templatePath}/qa/details`)
      },
      {
        path: 'qa/add',   // 发布问题
        name: 'SiteQaAdd',
        meta:{
          title:'发布问题',
          keepAlive: true,
          isBack: false  // 判断页面是否返回过来的
        },
        component: () => import(/* webpackChunkName: "SiteQaAdd" */ `@/${templatePath}/qa/add`)
      },
      {
        path: 'pay/qa/order',   // 问题支付订单
        name: 'SiteQaOrder',
        meta:{
          title:'确认订单'
        },
        component: () => import(/* webpackChunkName: "SiteQaOrder" */ `@/${templatePath}/qaOrder`)
      },
      {
        path: 'choise/teacher',   // 选择教师
        name: 'SiteChoiseTeacher',
        meta:{
          title:'选择教师'
        },
        component: () => import(/* webpackChunkName: "SiteChoiseTeacher" */ `@/${templatePath}/teacher/choise.vue`)
      },
      {
        path: 'teacher/:id',   // 教师主页
        name: 'SiteTeacherIndex',
        meta:{
          title:'教师主页'
        },
        component: () => import(/* webpackChunkName: "SiteTeacher" */ `@/${templatePath}/teacher/index`)
      },
      {
        path: 'home',
        name: 'SiteHome',
        component: () => import(/* webpackChunkName: "SiteHome" */ `@/${templatePath}/home`),
        beforeEnter:(to, from ,next)=>{
          to.meta.title = `${title}-个人中心`
          next()
        }
      },
      {
        path: 'home/course',
        name: 'SiteMycourse',
        component: () => import(/* webpackChunkName: "SiteMycourse" */ `@/${templatePath}/home/course.vue`),
        meta: { title: `个人中心-我的课程` }
      },
      {
        path: 'home/collection',
        name: 'SiteMyCollection',
        component: () => import(/* webpackChunkName: "SiteMyCollection" */ `@/${templatePath}/home/collection.vue`),
        meta: { title: `个人中心-我的收藏` }
      },
      {
        path: 'home/follow',
        name: 'SiteMyFollow',
        component: () => import(/* webpackChunkName: "SiteMyFollow" */ `@/${templatePath}/home/follow.vue`),
        meta: { title: `个人中心-我的关注` }
      },
      {
        path: 'home/questions',
        name: 'SiteMyQuestions',
        component: () => import(/* webpackChunkName: "SiteMyQuestions" */ `@/${templatePath}/home/questions.vue`),
        meta: { title: `个人中心-我的问题` }
      },
      {
        path: 'home/question/:id',   // 问题详情
        name: 'SiteMyQuestionDetials',
        meta:{
          title:'问题详情'
        },
        component: () => import(/* webpackChunkName: "SiteMyQuestionDetials" */ `@/${templatePath}/home/detailsQuestion.vue`)
      },
      {
          path: 'home/card/create',   // 个人名片创建
          name: 'SiteCardCreate',
          meta:{
              title:'个人名片创建'
          },
          component: () => import(/* webpackChunkName: "SiteCardCreate" */ `@/${templatePath}/home/card/create`)
      },
      {
        path: 'apply/look',   // 申请观看
        name: 'SiteApplyLook',
        meta:{
          title:'申请免费观看',
        },
        component: () => import(/* webpackChunkName: "SiteApplyLook" */ `@/${templatePath}/apply/look.vue`)
      },
      {
          path: 'search', // 搜索
          name: 'SiteSearch',
          component: () => import(/* webpackChunkName: "SiteSearch" */ `@/${templatePath}/search`),
          meta: { title: '搜索'}
      },
      {
          path: 'card',   // 个人名片列表
          name: 'SiteCardList',
          meta:{
            title:'名片列表'
          },
          component: () => import(/* webpackChunkName: "SiteCardList" */ `@/${templatePath}/card/lists`)
      },
      {
          path: 'card/:id',   // 个人名片
          name: 'SiteCard',
          meta:{
            title:'个人名片'
          },
          component: () => import(/* webpackChunkName: "SiteCard" */ `@/${templatePath}/card/index`)
      },
      //***************************************课程包逻辑页面********************************************************************* 
      {
          path: 'sale',
          name: 'SiteSale',
          component: () => import(/* webpackChunkName: "SiteSale" */ `@/${templatePath}/sale`),
          meta: { title: '集团推广主页'}
      },
      {
          path: 'sale/qrcode/create',
          name: 'SiteSaleQrcodeCreate',
          component: () => import(/* webpackChunkName: "SiteSaleQrcodeCreate" */ `@/${templatePath}/sale/qrcode`),
          meta: { title: '创建推广二维码'}
      },
      {
          path: 'sale/qrcode/:saleQrcodeId', // saleQrcode表数据id
          name: 'SiteSaleQrcodeShare',
          component: () => import(/* webpackChunkName: "SiteSaleQrcodeShare" */ `@/${templatePath}/sale/qrcode/share`),
          meta: { title: '推广二维码分享'}
      },
      {
          path: 'company/:saleQrcodeId', // 公司主页，销售人员分分享给审核人员的页面
          name: 'SiteCompany',
          component: () => import(/* webpackChunkName: "SiteCompany" */ `@/${templatePath}/sale/company`),
          meta: { title: '公司主页'}
      },
      {
        path: 'home/package', 
        name: 'SiteHomePackage',
        component: () => import(/* webpackChunkName: "SiteHomePackage" */ `@/${templatePath}/sale/my`),
        meta: { title: '课程包管理'},
      },
      {
          path: 'sale/qrcode/join/people', // 加入某个公司的成员列表
          name: 'SiteSaleQrcodeJoinPeople',
          component: () => import(/* webpackChunkName: "SiteSaleQrcodeJoinPeople" */ `@/${templatePath}/sale/people`),
          meta: { title: '成员列表'}
      },
      {
          path: 'sale/qrcode/join/form', // 加入人员扫描需填写的表单（扫描二维码跳转的连接）
          name: 'SiteSaleQrcodeJoin',
          component: () => import(/* webpackChunkName: "SiteSaleQrcodeJoin" */ `@/${templatePath}/sale/qrcode/form`),
          meta: { title: '加入人员填写基本信息'}
      },
      {
          path: 'company/course/:saleQrcodeId', // 公司待审核课程列表
          name: 'SiteCompanyCourse',
          component: () => import(/* webpackChunkName: "SiteCompanyCourse" */ `@/${templatePath}/sale/company/course`),
          meta: { title: '待审核课程'}
      },
      {
          path: 'my/package/:saleQrcodeId', // 购买的课程包
          name: 'SiteMyPackage',
          component: () => import(/* webpackChunkName: "SiteMyPackage" */ `@/${templatePath}/sale/package/my`),
          meta: { title: '我的课程包'}
      },
      {
          path: 'package', // 课程包购买页面
          name: 'SitePackage',
          component: () => import(/* webpackChunkName: "SitePackage" */ `@/${templatePath}/sale/package`),
          meta: { title: '课程包'}
      },
      {
          path: 'offline/pay/bank', // 线下支付获取银行卡及订单信息
          name: 'SiteOfflinePayBank',
          component: () => import(/* webpackChunkName: "SiteOfflinePayBank" */ `@/${templatePath}/sale/offlinePay/bank`),
          meta: { title: '线下支付'}
      },
      {
          path: 'offline/pay/manage',
          name: 'SiteOfflinePayManage',
          component: () => import(/* webpackChunkName: "SiteOfflinePayManage" */ `@/${templatePath}/sale/offlinePay/manage`),
          meta: { title: '线下支付管理'}
      },
      {
          path: 'offline/pay/upload/certify',
          name: 'SiteOfflinePayUpload',
          component: () => import(/* webpackChunkName: "SiteOfflinePayUpload" */ `@/${templatePath}/sale/offlinePay/upload`),
          meta: { title: '线下支付上传凭证'}
      },
      //***************************************课程包逻辑页面 end********************************************************************* 

    ]
  }